#ifndef BATTLE_HPP_INCLUDED
#define BATTLE_HPP_INCLUDED

#include <vector>

#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>

#include "formula_callable.hpp"
#include "texture.hpp"
#include "unit.hpp"
#include "widget.hpp"

namespace game {

class battle_unit;
typedef boost::shared_ptr<battle_unit> battle_unit_ptr;

class battle_projectile;
typedef boost::shared_ptr<battle_projectile> battle_projectile_ptr;

class battle : public game_logic::formula_callable {
public:
	static battle* current();
	
	battle(unit_ptr attacker, unit_ptr defender);
	~battle();
	bool done() const;
	void process();
	void draw() const;
private:
	bool fighting_finished() const;

	variant get_value(const std::string& key) const;

	unit_ptr attacker_, defender_;

	std::vector<battle_unit_ptr> attacker_units_, defender_units_;
	std::vector<battle_projectile_ptr> projectiles_;

	int attacker_attack_, attacker_defense_, defender_attack_, defender_defense_;
	battle_unit_ptr find_target(battle_unit_ptr attacker, const std::vector<battle_unit_ptr>& targets);

	mutable GLfloat fade_;

	int cycles_at_end_;

	gui::widget_ptr attacker_description_, defender_description_;
};

typedef boost::intrusive_ptr<battle> battle_ptr;
typedef boost::intrusive_ptr<const battle> const_battle_ptr;

}

#endif
